package com.example.strategy;

import com.example.Discount;
import com.example.fruit.Fruit;

import java.math.BigDecimal;
import java.util.List;

/**
 * 折扣+满减
 */
public class StrategyC implements Strategy{
    @Override
    public BigDecimal getMoney(List<Fruit> fruitList, List<Discount> discountList) {
        BigDecimal all = new BigDecimal(0);
        for (Fruit fruit : fruitList) {
            for (Discount discount : discountList) {
                if(fruit.getName().equals(discount.getName())){
                    all = all.add(fruit.getSum().multiply(discount.getDiscount()));
                    break;
                }
                all = all.add(fruit.getSum());
            }
        }
        if (all.compareTo(BigDecimal.valueOf(100)) > -1) {
            all = all.subtract(BigDecimal.valueOf(10));
        }
        return all.setScale(2, BigDecimal.ROUND_HALF_UP);
    }
}
